<?php
header("Content-type:text/html; charset=utf-8");
include ("../conn.php");
include ("../include/function.php");
include("../include/pager.php");

$tip ="";
$id="";
if(isset($_GET['id']))	$id = $_GET['id'];
$menuname="";
if(isset($_GET['menuname']))	$menuname = $_GET['menuname'];
$parentid="";
if(isset($_GET['parentid']))	$parentid = $_GET['parentid'];
$pparentid="";
if(isset($_GET['pparentid']))	$pparentid=$_GET['pparentid'];
$parentname="";
if(isset($_GET['parentname']))	$parentname = $_GET['parentname'];

$act = "";
if(isset($_GET['act'])){
	$act =$_GET['act'];
}

//删除操作
if(isset($_GET['id']) && isset($_GET['act']) && $_GET['act']=="del")
{
	$selectSQL = "select foriginalfile from ".$databasepre."file where parentid='".$id."'";
	//echo $selectSQL;
	$query = mysql_query($selectSQL);
	while($row=mysql_fetch_array($query))
	{
		@unlink("..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."original".DIRECTORY_SEPARATOR.$row['foriginalfile']);
		@unlink("..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."big".DIRECTORY_SEPARATOR.$row['foriginalfile']);
		@unlink("..".DIRECTORY_SEPARATOR."upload".DIRECTORY_SEPARATOR."small".DIRECTORY_SEPARATOR.$row['foriginalfile']);
	}
	$deleteSQL="delete from ".$databasepre."file where parentid='".$id."'";
	mysql_query($deleteSQL);

	$deleteSQL="delete from ".$databasepre."general where id='".$id."'";
	//echo $deleteSQL;
	mysql_query($deleteSQL);
	$tip ="删除成功！";
	//echo $tip;
}
//推荐操作
if(isset($_GET['id']) && isset($_GET['act']) && $_GET['act']=="recommend")
{
	$recommend = $_GET['recommend'];
	if($recommend==0){
		$recommend = 1;
	}else{
		$recommend = 0;
	}
	$updateSQL="update ".$databasepre."general set isrecommend='".$recommend."',updatedate=now() where id='".$id."'";
	//echo $deleteSQL;
	mysql_query($updateSQL);
	$tip ="操作成功！";
}

?>
<html><head>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<link href="images/skin.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #EEF2FB;
}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td width="17" valign="top" background="images/mail_leftbg.gif"><img src="images/left-top-right.gif" width="17" height="29" /></td>
    <td valign="top" background="images/content-bg.gif">
		<table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
		  <tr><td height="31"><div class="titlebt"><?php echo $parentname;?></div></td></tr>
		</table>
	</td>
    <td width="16" valign="top" background="images/mail_rightbg.gif"><img src="images/nav-right-bg.gif" width="16" height="29" /></td>
  </tr>
  <tr>
    <td valign="middle" background="images/mail_leftbg.gif">&nbsp;</td>
    <td valign="top" bgcolor="#F7F8F9">
	<!-- 网页内容部分开始 -->


	<table width="100%" height="138" border="0" cellpadding="0" cellspacing="0">
      <tr><td height="13" valign="top">&nbsp;</td></tr>
	  <tr><td class="left_txt">当前位置：<?php echo $parentname;?> - > <?php echo $_GET['menuname']?></td></tr>
	  <!-- 一根线 -->
	  <tr><td><table width="100%" height="1" border="0" cellpadding="0" cellspacing="0" bgcolor="#CCCCCC"><tr><td></td></tr></table></td></tr>
	  <!-- 说明信息 -->

	  <tr><td><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="nowtable">
				  <tr><td class="left_bt2">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo $_GET['menuname'];?>
				  【<a href="admin_list_one.php?act=create&parentid=<?php echo $parentid;?>&pparentid=<?php echo $pparentid;?>&parentname=<?php echo urlencode($parentname);?>&menuname=<?php echo urlencode($menuname);?>"> 新 增 </a>】
					<span id="tip_id" style='color:#FF0000; font-size:16px; font-family:"微软雅黑","黑体","宋体"'><?php echo $tip; ?></span>
					</td>
					
					</tr>
				</table>
		</td>
      </tr>
	  <tr><td>
	  
	  <form method=POST action="">
	  <table width="100%" border="0" cellspacing="0" cellpadding="0" align=left>
				
			<tr bgcolor="#669966">
				<th width="1%" class="left_txt" align=left></th>
				<th width="40%" height="30" class="left_txt2" align=center>名称</th>
				<th width="10%" height="30" class="left_txt2" align=center>首页推荐</th>
				<!--<th width="5%" height="30" class="left_txt2" align=left>图片</th>
				<th width="10%" class="left_txt2" align=left>排序[升序]</th>-->
				<th width="15%" class="left_txt2" align=left>发布时间</th>
				<th width="19%" class="left_txt2" align=left>操作</th>
			</tr>
			<?php
			$tdstyle="";
			$tdi = 0;
			
			//定义查询语句SQL
			$sql="select * from ".$databasepre."general where parentid='".$parentid."' order by seq asc,id desc";
			$phpfile = 'admin_list_page.php?parentid='.$parentid
						.'&pparentid='.$pparentid
						.'&menuname='.urlencode($menuname)
						.'&parentname='.urlencode($parentname);//页面文件名
			$page= isset($_GET['page'])?$_GET['page']:1;//默认页码
			
			$counts = mysql_num_rows(mysql_query($sql));//获取需要的数据总条数
			$getpageinfo = page($page,$counts,$phpfile,20,10);//调用函数，生成分页HTML 和 SQL LIMIT 子句
			if($counts>0)$sql.=$getpageinfo['sqllimit'];//组合完整的SQL语句
			$data = $row = array();//初始化数组
			$result = mysql_query($sql);//获取结果集

			
			
			//echo $sql;
			while($row=mysql_fetch_array($result))
			{
				$tdi = $tdi + 1;
				if($tdi%2 == 1) { $tdstyle = "f2f2f2"; }else{ $tdstyle = ""; }
				$picnum = getOneFiledbySQL("select count(*) AS filedname from ".$databasepre."file where parentid=".$row['id']);
				$piccolor = $picnum==0?"style='color:red'":$picnum;
				
				$isrecommendname="<span style='color:red;'>是</span>";
				if($row['isrecommend']==0){
					$isrecommendname="否";
				}
				
				echo '<tr bgcolor='.$tdstyle.'>';
				echo '<td height="30"></td>';
				echo '<td align=left>'.$row['field11'].'</td>';
				echo '<td align=center '.$piccolor.'><a href=?act=recommend&parentid='.$row['parentid'].'&pparentid='.$row['pparentid'].'&parentname='.urlencode($parentname).'&menuname='.urlencode($menuname).'&id='.$row['id'].'&page='.$page.'&recommend='.$row['isrecommend'].'>'.$isrecommendname.'</a></td>';//
				//echo '<td align=left '.$piccolor.'>'.$picnum.'张</td>';//
				//echo '<td align=left >'.$row['seq'].'</td>';
				echo '<td align=left>'.$row['createdate'].'</td>';
				echo '<td align=left><a href="admin_list_one.php?act=update&parentid='.$row['parentid'].'&pparentid='.$row['pparentid'].'&parentname='.urlencode($parentname).'&menuname='.urlencode($menuname).'&id='.$row['id'].'&page='.$page.'">修改</a> -- ' .
						'<a href=?act=del&parentid='.$row['parentid'].'&pparentid='.$row['pparentid'].'&parentname='.urlencode($parentname).'&menuname='.urlencode($menuname).'&id='.$row['id'].'&page='.$page.'>删除</a></td>';
				echo '</tr>';
			}
			if($tdi == 0) {echo "<tr><td h colspan=5 height='100px' align=center>暂无信息！</td></tr>";}
			?>


		<tr  bgcolor="#669966">
		<td colspan="6" >
		<?php if($counts>0) {echo $getpageinfo['pagecode'];}//显示分页的html代码 ?>
		</td>
		</tr>
		
	  </table>
	  </form>
			  
			</td>
		</tr>



	 </table>






	<!-- 网页内容部分结束 -->
	</td>
    <td background="images/mail_rightbg.gif">&nbsp;</td>
  </tr>
  <tr>
    <td valign="bottom" background="images/mail_leftbg.gif"><img src="images/buttom_left2.gif" width="17" height="17" /></td>
    <td background="images/buttom_bgs.gif"><img src="images/buttom_bgs.gif" width="17" height="17"></td>
    <td valign="bottom" background="images/mail_rightbg.gif"><img src="images/buttom_right2.gif" width="16" height="17" /></td>
  </tr>
</table>
</body>
</html>
